jenkins pipeline example¶
this project is parameterized(string, choice)
pipeline
pipeline { agent any stages { stage('checkout') { when { expression { return params.action == 'deploy' } } steps { dir('/git/projectName/') { checkout([$class: 'GitSCM', branches: [[name: "${tag}"]], doGenerateSubmoduleConfigurations: false, extensions: [], gitTool: 'Default', submoduleCfg: [], userRemoteConfigs: [[credentialsId: '12345678-1234-1234-1234-123456789012', url: 'https://chenshi.de/projectName']] ]) } } } stage('build') { when { expression { return params.action == 'deploy' } } steps { dir('/git/projectName/') { sh''' mvn clean package -Ddocker-image.tag=${tag} -DpushImage ''' } } } stage('deploy') { when { expression { return params.action == 'deploy' } } steps { sh ''' /yaml/test-projectName.sh ${tag} ''' } } stage('rollback') { when { expression { return params.action == 'rollback' } } steps { sh """ /yaml/rollback.sh ${JOB_NAME} ${tag} """ } } } }